import Tips from './tips'
import wepy from 'wepy'
export default class wxUtils {
  static mapUrl = []
  /**
   * 如果能够后退（多层），则navigaetBack，否则调用navigateTo
   */
  static backOrnavigateTo(url) {
    const pages = getCurrentPages()
    const index = pages.findIndex(item =>(item.route.split('/')[1]) == url)
    if(index === -1) {
      wx.navigateTo({
        url
      })
    } else {
      const delta = pages.length - 1 - index
      wx.navigateBack({
        delta:delta
      })
    }
  }
  // 监听网络状态
  static eventNet() {
      let flag = true
      wx.onNetworkStatusChange(({networkType}) => {
          // console.log(networkType)
        if (networkType === 'none' || networkType === '2g') {
          flag = false

        } else {
          flag = true
          // console.log(networkType)

        }
      })
      // console.log(a)
      // return new Promise(function(resolve, reject) {})
  }
}
